import com.alibaba.druid.pool.DruidDataSource;

import java.sql.SQLException;

public class Main {
    public static void main(String[] args) {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/jdbc");
        dataSource.setUsername("root");
        dataSource.setPassword("1626");
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setInitialSize(10);
        dataSource.setMaxActive(20);
        dataSource.setMinIdle(5);
        dataSource.setMaxWait(60000);
        dataSource.setTimeBetweenEvictionRunsMillis(60000);
        dataSource.setMinEvictableIdleTimeMillis(300000);
        dataSource.setValidationQuery("SELECT 1");


        try{
            if(dataSource.getConnection() != null){
                System.out.println("连接成功");
            }else{
                System.out.println("连接失败");
            }
        }catch(SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
